package com.secsbrain.cloudconsole.web.controller;

import java.util.List;

import com.secsbrain.common.ErrorCodeEnum;
import com.secsbrain.common.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.secsbrain.cmdb.client.iface.OpsInfoService;
import com.secsbrain.common.ResponseVo;

@RestController
@RequestMapping("/server")
public class ServerController {
    
    private static final Logger logger = LoggerFactory.getLogger(ServerController.class);
    
    @Autowired
	private OpsInfoService opsInfoService;
    
    /**
     * @apiVersion 1.0.0
     * @api {GET} /server/getEnv 获取应用环境
     * 
     * @apiGroup Server
     * 
     * @apiSuccess {String[]} data         应用环境列表
     * 
     */
    @RequestMapping(value = "/getEnv", method = RequestMethod.GET)
	public ResponseResult<List<String>> getEnv(){
		ResponseVo<List<String>> envListVo=opsInfoService.queryEnvList();
		if (!envListVo.isSuccess()){
			return new ResponseResult<>(ErrorCodeEnum.ERROR_COMMON_SYSTEM.getCode(),envListVo.getMsg());
		}
		return new ResponseResult<>(envListVo.getData());
	}
    
    /**
     * @apiVersion 1.0.0
     * @api {GET} /server/getImageOption 获取镜像选项
     * 
     * @apiGroup Server
     * 
     * @apiSuccess {String[]} data         镜像列表
     * 
     */
    @RequestMapping(value = "/getImageOption", method = RequestMethod.GET)
	public ResponseResult<List<String>> getImageOption(){
		ResponseVo<List<String>> imageOptionListVo=opsInfoService.queryImageOptionList();
		if (!imageOptionListVo.isSuccess()){
			return new ResponseResult<>(ErrorCodeEnum.ERROR_COMMON_SYSTEM.getCode(),imageOptionListVo.getMsg());
		}
		return new ResponseResult<>(imageOptionListVo.getData());
	}
    
}
